<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" left-icon="lock" label-width="200" label="原密码" prop="pw">
				<u-input placeholder="请输入登录密码" v-model="model.pw" type="password"></u-input>
			</u-form-item>
			<u-form-item :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label="新密码" label-width="200" prop="dpw" left-icon="lock">
				<u-input :password-icon="true" maxlength="6" type="password" v-model="model.dpw" placeholder="请输入交易密码"></u-input>
			</u-form-item>
		</u-form>
		<view style="margin-top: 60rpx;">
			<u-button @click="submit" ripple-bg-color="#656565" :plain="false" :ripple="true" type="primary">提交</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		let that = this;
		return {
			model: {
				pw: '',
				dpw: ''
			},
			rules: {
				pw:[
					{
						required: true,
						message: '请输入原密码',
						trigger: ['change','blur'],
					}
				],
				dpw: [
					{
						required: true,
						message: '请输入交易密码',
						trigger: ['change','blur'],
					},
					{
						// 正则不能含有两边的引号
						pattern: /^\d{6}$/,
						message: '交易密码只能是6位数字',
						trigger: ['change','blur'],
					}
				],
			},
			errorType: ['message'],
		};
	},
	onLoad() {

	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		submit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					console.log('验证通过');
				} else {
					console.log('验证失败');
				}
			});
		},
	}
};
</script>

<style scoped lang="scss">
.wrap {
	padding: 30rpx;
}

.agreement {
	display: flex;
	align-items: center;
	margin: 40rpx 0;

	.agreement-text {
		padding-left: 8rpx;
		color: $u-tips-color;
	}
}
</style>
